package com.tcm.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tcm.entity.Term;
import com.tcm.entity.vo.TermListResult;
import com.tcm.mapper.TermMapper;
import com.tcm.service.TermService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 学期业务接口实现类
 * @author Guqier
 * @version 1.0
 * @date 2023/7/18 12:09
 */
@Service
public class TermServiceImpl extends ServiceImpl<TermMapper, Term> implements TermService {

    /**
     * 获取学期展示数据列表
     * @return 学期展示数据列表
     */
    @Override
    public List<TermListResult> getTermList(){
        List<Term> terms = this.list();
        long time = new Date().getTime();
        return terms
                .stream()
                .filter(term -> term.getStartTime().getTime() < time)
                .map(term -> {
                    TermListResult termListResult = new TermListResult();
                    BeanUtils.copyProperties(term, termListResult);
                    return termListResult;
                })
                .collect(Collectors.toList());
    }

}
